package com.huijutao.fragment;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.huijutao.CustomView.WebViewSetting;
import com.huijutao.MyApp;
import com.huijutao.R;
import com.huijutao.callback.ABSFragment;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link HcHaiContentFragment.HcContentCallBack} interface
 * to handle interaction events.
 * Use the {@link HcHaiContentFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HcHaiContentFragment extends ABSFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private static final String ARG_PARAM3 = "param3";
    private static final String ARG_PARAM4 = "param4";
    private static final String ARG_PARAM5 = "param5";
    private static final String ARG_PARAM6 = "param6";
    private static final String ARG_PARAM7 = "param7";



    // TODO: Rename and change types of parameters
    private String title;
    private String subtitle;
    private String img_path;
    private String go_websit;
    private String go_url;
    private String praise;
    private String content;
    private HcContentCallBack mListener;

    // TODO: Rename and change types and number of parameters
    public static HcHaiContentFragment newInstance(String img_path, String title, String subtitle,
                                                String go_websit, String go_url, String praise,String content) {
        HcHaiContentFragment fragment = new HcHaiContentFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, img_path);
        args.putString(ARG_PARAM2, title);
        args.putString(ARG_PARAM3, subtitle);
        args.putString(ARG_PARAM4, go_websit);
        args.putString(ARG_PARAM5, go_url);
        args.putString(ARG_PARAM6, praise);
        args.putString(ARG_PARAM7, content);
        fragment.setArguments(args);
        return fragment;
    }

    public HcHaiContentFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            img_path = getArguments().getString(ARG_PARAM1);
            title = getArguments().getString(ARG_PARAM2);
            subtitle = getArguments().getString(ARG_PARAM3);
            go_websit = getArguments().getString(ARG_PARAM4);
            go_url = getArguments().getString(ARG_PARAM5);
            praise = getArguments().getString(ARG_PARAM6);
            content=getArguments().getString(ARG_PARAM7);
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {



        View view= inflater.inflate(R.layout.fragment_hc_you_hui_content, container, false);
        ImageView image= (ImageView) view.findViewById(R.id.hc_youhui_content_image);
        TextView textContentTitle = (TextView) view.findViewById(R.id.hc_youhui_content_title);
        TextView textSub= (TextView) view.findViewById(R.id.hc_youhui_content_subtitle);
        textSub.setText(subtitle);
        textContentTitle.setText(title);
        WebView webView = (WebView) view.findViewById(R.id.hc_youhui_content_webview);
        WebViewSetting.setWebView(webView);
        webView.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
        MyApp.mImageXutils.display(image,img_path);
        return view;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.hcContentCallBack(uri);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (HcContentCallBack) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void setType(int type) {

    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface HcContentCallBack {
        // TODO: Update argument type and name
        public void hcContentCallBack(Uri uri);
    }
}
